<?php
/*
 * Created on 04.01.2006
 *
 */

m2import('phpinchains/Filter.php');

/**
 * Filter which calls the old admin view controller views
 */
class DispatchLegacyAdminFilter extends phpinchains_Filter
{

    var $adminDir;
    var $targetFile;
    var $targetExt;

    function init (& $config)
    {
        $this->adminDir   = $config['admin-dir'];
        $this->targetFile = $config['target-file'];
        $this->targetExt  = $config['target-extension'];
    }

    function doFilter (& $env, & $chain)
    {
        // FIXME - Firefox bug: sends duplicate request
        if (headers_sent())
            exit;
        $etcPath = ETC_PATH.'/';
        $ChainsWrapped = true;
        $GLOBALS['innerScriptName'] = $this->targetFile.".".$this->targetExt;
        if (file_exists($this->adminDir.$this->targetFile.'.'.$this->targetExt))
        {
            $type = 'text/html';
            /*switch ($this->targetExt)
            {
                case 'gif':
                    $type = 'image/gif';
                    break;
                case 'jpg':
                    $type = 'image/jpeg';
                    break;
                case 'png':
                    $type = 'image/x-png';
                    break;
            }*/
            $ctx = & base_ApplicationContext::getInstance();
            $env = & $ctx->getEnvWrapper();
            header("Content-Type: $type");
            include($this->adminDir.$this->targetFile.'.'.$this->targetExt);
        }
        else
        {
            print $this->adminDir.$this->targetFile . " was not found!";
        }
    }

}

?>